#ifndef PLATFORM_CHECK_H
#define PLATFORM_CHECK_H

#include <stdio.h>

/* 编译器检查 */
#if defined(_MSC_VER)
    #define COMPILER_MSVC 1
#elif defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
    #define COMPILER_GCC 1
#elif defined(__clang__)
    #define COMPILER_CLANG 1
#elif defined(__ICC) || defined(__INTEL_COMPILER)
    #define COMPILER_ICC 1       // Intel C++ Compiler
#elif defined(__ARMCC__)
    #define COMPILER_ARMCC 1     // ARM Compiler
#elif defined(__xlC__) || defined(__xlc__)
    #define COMPILER_XLC 1       // IBM XL C/C++
#elif defined(__TI_COMPILER_VERSION__)
    #define COMPILER_TI 1        // Texas Instruments Compiler
#else
    #error "不支持的编译器，请扩展编译器检查宏"
#endif

/* 操作系统检查 */
#if defined(__ANDROID__)
    #define OS_ANDROID 1
#elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) || defined(__IPHONE_OS__)
    #define OS_IOS 1
#elif defined(_WIN32) || defined(_WIN64)
    #define OS_WINDOWS 1
#elif defined(__linux__)
    #define OS_LINUX 1
#elif defined(__FreeBSD__)
    #define OS_FREEBSD 1
#elif defined(__OpenBSD__)
    #define OS_OPENBSD 1
#elif defined(__NetBSD__)
    #define OS_NETBSD 1
#elif defined(__DragonFly__)
    #define OS_DRAGONFLYBSD 1
#elif defined(__HAIKU__)
    #define OS_HAIKU 1
#elif defined(__sun__) && defined(__SVR4)
    #define OS_SOLARIS 1
#elif defined(__AIX__)
    #define OS_AIX 1
#elif defined(__hpux__)
    #define OS_HPUX 1
#elif defined(__QNX__)
    #define OS_QNX 1
#elif defined(__APPLE__) && defined(__MACH__)
    #define OS_MACOS 1
#else
    #error "不支持的操作系统，请扩展操作系统检查宏"
#endif

/* CPU 架构检查（可选扩展） */
#if defined(__x86_64__) || defined(_M_X64)
    #define ARCH_X86_64 1
#elif defined(__i386__) || defined(_M_IX86)
    #define ARCH_X86 1
#elif defined(__arm__) || defined(_M_ARM)
    #define ARCH_ARM 1
#elif defined(__aarch64__) || defined(_M_ARM64)
    #define ARCH_AARCH64 1
#elif defined(__powerpc__) || defined(__ppc__)
    #define ARCH_PPC 1
#elif defined(__riscv)
    #define ARCH_RISCV 1
#endif

/* 编译器和平台信息打印（调试用） */
static void print_compiler_platform_info() {
    printf("编译信息: ");
    
    // 打印编译器信息
#ifdef COMPILER_MSVC
    printf("MSVC (v%d)", _MSC_VER);
#elif COMPILER_GCC
    printf("GCC (v%d.%d.%d)", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
#elif COMPILER_CLANG
    printf("Clang (v%d.%d.%d)", __clang_major__, __clang_minor__, __clang_patchlevel__);
#elif COMPILER_ICC
    printf("Intel ICC (v%d.%d)", __INTEL_COMPILER / 100, (__INTEL_COMPILER % 100) / 10);
#elif COMPILER_ARMCC
    printf("ARMCC (v%d.%d)", __ARMCC_VERSION / 100000, (__ARMCC_VERSION % 100000) / 10000);
#elif COMPILER_XLC
    printf("IBM XL C (v%d)", __xlC_VERSION__);
#elif COMPILER_TI
    printf("TI Compiler (v%d)", __TI_COMPILER_VERSION__);
#endif

    printf(" on ");
    
    // 打印操作系统信息
#ifdef OS_WINDOWS
    printf("Windows");
#elif OS_LINUX
    printf("Linux");
#elif OS_MACOS
    printf("macOS");
#elif OS_IOS
    printf("iOS");
#elif OS_ANDROID
    printf("Android");
#elif OS_FREEBSD
    printf("FreeBSD");
#elif OS_OPENBSD
    printf("OpenBSD");
#elif OS_NETBSD
    printf("NetBSD");
#elif OS_DRAGONFLYBSD
    printf("DragonFlyBSD");
#elif OS_HAIKU
    printf("Haiku");
#elif OS_SOLARIS
    printf("Solaris");
#elif OS_AIX
    printf("AIX");
#elif OS_HPUX
    printf("HP-UX");
#elif OS_QNX
    printf("QNX");
#endif

    // 打印CPU架构信息（如果已定义）
#ifdef ARCH_X86_64
    printf(" (x86_64)");
#elif ARCH_X86
    printf(" (x86)");
#elif ARCH_ARM
    printf(" (ARM)");
#elif ARCH_AARCH64
    printf(" (AArch64)");
#elif ARCH_PPC
    printf(" (PowerPC)");
#elif ARCH_RISCV
    printf(" (RISC-V)");
#endif

    printf("\n");
}

#endif // PLATFORM_CHECK_H
